//package org.znxs.znxsframe.mq_test;
//
//import com.rabbitmq.client.Channel;
//import com.rabbitmq.client.Connection;
//import com.rabbitmq.client.ConnectionFactory;
//import com.rabbitmq.client.DeliverCallback;
//
//import java.util.Scanner;
//
//public class DlxDirectProducer {
//
//    // 死信交换机
//    private static final String DEAD_EXCHANGE_NAME = "dlx-direct-exchange";
//    // 普通交换机
//    private static final String WORK_EXCHANGE_NAME = "direct2-exchange";
//
//
//    public static void main(String[] argv) throws Exception {
//        // 创建连接
//        ConnectionFactory factory = new ConnectionFactory();
//        factory.setHost("localhost");
//        try (Connection connection = factory.newConnection();
//             Channel channel = connection.createChannel()) {
//
//            // 声明死信交换机
//            channel.exchangeDeclare(DEAD_EXCHANGE_NAME, "direct");
//
//            // 声明死信交换机分配的消息队列  laoban
//            String queueName = "laoban_dlx_queue";
//            channel.queueDeclare(queueName, true, false, false, null);
//            channel.queueBind(queueName, DEAD_EXCHANGE_NAME, "laoban");
//
//            // 声明死信交换机分配的队列  waibao
//            String queueName2 = "waibao_dlx_queue";
//            channel.queueDeclare(queueName2, true, false, false, null);
//            channel.queueBind(queueName2, DEAD_EXCHANGE_NAME, "waibao");
//
//            DeliverCallback laobanDeliverCallback = (consumerTag, delivery) -> {
//                String message = new String(delivery.getBody(), "UTF-8");
//                // 拒绝消息
//                channel.basicNack(delivery.getEnvelope().getDeliveryTag(), false, false);
//                System.out.println(" [laoban] Received '" +
//                        delivery.getEnvelope().getRoutingKey() + "':'" + message + "'");
//            };
//
//            DeliverCallback waibaoDeliverCallback = (consumerTag, delivery) -> {
//                String message = new String(delivery.getBody(), "UTF-8");
//                // 拒绝消息
//                channel.basicNack(delivery.getEnvelope().getDeliveryTag(), false, false);
//                System.out.println(" [waibao] Received '" +
//                        delivery.getEnvelope().getRoutingKey() + "':'" + message + "'");
//            };
//
//            // 死信队列消费
//            channel.basicConsume(queueName, false, laobanDeliverCallback, consumerTag -> {
//            });
//            channel.basicConsume(queueName2, false, waibaoDeliverCallback, consumerTag -> {
//            });
//
//
//            Scanner scanner = new Scanner(System.in);
//            while (scanner.hasNext()) {
//                String userInput = scanner.nextLine();
//                String[] strings = userInput.split(" ");
//                if (strings.length < 1) {
//                    continue;
//                }
//                String message = strings[0];
//                String routingKey = strings[1];
//
//                // 发布订阅
//                channel.basicPublish(WORK_EXCHANGE_NAME, routingKey, null, message.getBytes("UTF-8"));
//                System.out.println(" [x] Sent '" + message + " with routing:" + routingKey + "'");
//            }
//
//        }
//    }
//    //..
//}
